let search = (function () {
    let newData = []

    function render(data = []) {
        newData = [...newData, ...data]

        let page = ''

        newData.forEach(item => {
            
            item.img = item.img.replace('images', './assets/images');
            console.log(item.img);
            
            page += `
            <div class="nv-con-col">
                    <a href="../pages/${item.titlehref}">
                        ${item.img}
                    </a>
                    <p>
                        ${item.name}
                    </p>
                </div>
            `
        })
        $('.row').html(page)
        // 点击更多 多显示一行
        // console.log($('#info>.nv-con-col'));
        $('.nv-con-col').eq(7).click(function (e) {

            e.preventDefault();
      
          })
        $('.nv-con-col').eq(7).click(function () {
            console.log('1');
            $('.nv-con-col').eq(7).nextAll().slideToggle();
        })

    }
    $.ajax({
        url: 'http://chst.vip:1234/api/getindexmenu',
        catch:true    
        })
        .then(res => {
            console.log(res);
            render(res.result)
        })
})()

// 商品请求，渲染页面
let product = (function () {
    let newData = [] //接受请求到的数据
    function render(data = []) {
        newData = [...data, ...newData]
        // console.log(newData);
       
        
        $('.info').html(page)
        // 点击事件
        $('.info').on('click','li',function(){
            let proid = $(this).attr('proid');
            // console.log(proid);
            location.href = `../pages/moneyproduct.html?productid=${proid}`
        })
    }
    
    let uu = document.querySelector('ul')
    //1.发起请求获取列表数据

    //2.根据列表数据展示列表内容

    //3.需要将商品的productId绑定到元素上

    //4.点击元素进行跳转,跳到detail页面 并且要携带productId
    let el = "";
    fetch('http://chst.vip:1234/api/getmoneyctrl')
    
        .then(body => body.json())

        .then(res => {
            // console.log(res)
            res.result.forEach(item => {

                let regExp = /(?<=imgurl=)[^'"]*/;
               
                
                let r = item.productImg2.match(regExp);
                
                
               el+=` <li proid="${item.productId}">
                
<a href="../pages/xiangqing.html?productid=${item.productId} ">

<img src=${r[0]} height="100" alt="">
               


   <div class="infoR">
               <div class="title">
                   <h4>${item.productName}
                       <span>${item.productPinkage}</span>
                   </h4>
               </div>
               <div class="other">
                   <span class="mall fl">${item.productFrom}|${item.productTime}</span>

                   <em class="fr">
                       <i class="iconfont icon-xiaoxi "></i>
                       <span> ${item.productComCount}</span>
                   </em>

               </div>

           </div>
</div>
</a>
              
                </li>`
            })
            uu.innerHTML = el;
        })

        $('ul').on('click','li',function(){
            // console.log(this);
            let productid = $(this).attr("productid")
            // console.log($('productid'));?
            location.href = `../pages/xiangqing.html?productid=${productid}`
            console.log( location.href = `../pages/xiangqing.html?productid=${productid}`)
        })

})()